package org.example.game.history;

import java.util.HashMap;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/05/11 22:58
 */
public class Solution100302 {

    public static void main(String[] args) {
        Solution100302 solution100302 = new Solution100302();

        int[][] points = {{-22,-14},{-21,19},{13,13},{5,21},{-12,-2}};
        String s = "cedce";

        System.out.println(solution100302.maxPointsInsideSquare(points, s));
    }

    public int maxPointsInsideSquare(int[][] points, String s) {
        int max = 0;

        HashMap<Character, Integer[]> minMap = new HashMap<>();
        int index = 0;
        for(Character c : s.toCharArray()){

            int dis = Math.max(Math.abs(points[index][0]), Math.abs(points[index][1]));

            if(!minMap.containsKey(c)){
                Integer[] arr = new Integer[2];
                arr[0] = dis;
                minMap.put(c , arr);
            }else {
                if(dis < minMap.get(c)[0]){
                    minMap.get(c)[1] = minMap.get(c)[0];
                    minMap.get(c)[0] = dis;
                }else if(dis >= minMap.get(c)[0] && (minMap.get(c)[1] == null || dis < minMap.get(c)[1])){
                    minMap.get(c)[1] = dis;
                }
            }
            index++;
        }

        int mixDis = -2;
        for(Character c : minMap.keySet()){
            if(minMap.containsKey(c) && minMap.get(c)[1] != null
                    && (minMap.get(c)[1] < mixDis || mixDis == -2)){
                mixDis = minMap.get(c)[1];
            }
        }

        if(mixDis == -2){
            return minMap.size();
        }

        if(mixDis <= 0){
            return 0;
        }

        for(Character c : minMap.keySet()){
            if(minMap.containsKey(c)
                && minMap.get(c)[0] <= mixDis-1){
                max++;
            }
        }

        return max;
    }

}
